//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//

/*!
  \class plDouble plDouble.h <plDouble>
  \brief plDouble is a database aware integer.

  plDouble can be used and should be used in the same way as a normal integer.
 Make sure plDouble::Setup() is called before using the class.
Without calling plDouble::Setup(), the database doesn't know how to get or commit data.

  For example:
   \code

  plDouble test;
  test.Setup("test", this);
  test = 5.0;
  test += 10.0;
  test = test * test;

  double temp = test;
  temp = 1000;
  test = temp;

   \endcode

  */

//Our includes
#include "plDouble.h"
#include "plObject.h"
#include "plDatabase.h"

//////////////////////////////////////////////// Public ////////////////////////////////////////////////////

//Constructor
plDouble::plDouble() : plData() {
	Cached = false;
}

//Constructor
plDouble::plDouble(double value) : plData () {
	Value = value;
	Disabled = true;
}

//Copy constructor
plDouble::plDouble(const plDouble& obj) : plData(obj) {
	Copy(obj);
}

//Accessor
double plDouble::Data() {
        plData::GetData();
	return Value;
}

//Modifier
void plDouble::SetData(double value) {
	Value = value;
        plData::SetData();
}

	
//Operator overloading
void plDouble::operator=(double value) {
	SetData(value);
}

//Operator overloading
void plDouble::operator=(const plDouble& obj) {
	Copy(obj);
}

plDouble::operator double() {
	return Data();
}

//Does a smart copy of the object
void plDouble::Copy(const plDouble& obj) {
	SetData(obj.Value);
	Cached = obj.Cached;
}
	

//Binds the data with the statement
void plDouble::Bind(sqlite3_stmt* statement, int index) const {
	sqlite3_bind_double(statement, index, Value);
}

	
//Gets the data from the current statement
void plDouble::Column(sqlite3_stmt* statement, int index ) {
	Value = sqlite3_column_double(statement, index);
}


